// CDialogPrinterOptions.cpp : Implementierungsdatei
//

#include "stdafx.h"
#include "Charplan.h"
#include "CDialogPrinterOptions.h"
#include "CharplanDoc.h"
#include ".\cdialogprinteroptions.h"

// CDialogPrinterOptions-Dialogfeld

IMPLEMENT_DYNAMIC(CDialogPrinterOptions, CDialog)
CDialogPrinterOptions::CDialogPrinterOptions(CCharplanDoc* doc, CWnd* pParent /*=NULL*/)
        : CDialog(CDialogPrinterOptions::IDD, pParent)
{
    mpc_doc = doc;
}

CDialogPrinterOptions::~CDialogPrinterOptions()
{
}

void CDialogPrinterOptions::DoDataExchange(CDataExchange* pDX)
{
    TRACE(LOG_DODATA,_T("CDialogPrinterOptions::DoDataExchange - begin"));
    CDialog::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_COMBO1, mwnd_style_sort);
    DDX_Control(pDX, IDC_COMBO2, mwnd_spell_sort);
    DDX_Control(pDX, IDC_CHECK4, mwnd_styles_no);
    DDX_Control(pDX, IDC_CHECK1, mwnd_styles_all);
    DDX_Control(pDX, IDC_CHECK5, mwnd_spells);
    DDX_Control(pDX, IDC_CHECK2, mwnd_spells_all);
    DDX_Control(pDX, IDC_CHECK7, mwnd_spell_description);
    DDX_Control(pDX, IDC_CHECK3, mwnd_no_ras);
    DDX_Control(pDX, IDC_CHECK6, mwnd_all_ras);
    TRACE(LOG_DODATA,_T("CDialogPrinterOptions::DoDataExchange - end"));

}


BEGIN_MESSAGE_MAP(CDialogPrinterOptions, CDialog)
    ON_BN_CLICKED(IDC_CHECK4, OnBnClickedCheck4)
    ON_BN_CLICKED(IDC_CHECK5, OnBnClickedCheck5)
    ON_CBN_SELCHANGE(IDC_COMBO1, OnCbnSelchangeCombo1)
    ON_BN_CLICKED(IDC_CHECK1, OnBnClickedCheck1)
    ON_BN_CLICKED(IDC_CHECK2, OnBnClickedCheck2)
    ON_BN_CLICKED(IDC_CHECK7, OnBnClickedCheck7)
    ON_BN_CLICKED(IDC_CHECK3, OnBnClickedCheck3)
    ON_BN_CLICKED(IDC_CHECK6, OnBnClickedCheck6)
END_MESSAGE_MAP()


// CDialogPrinterOptions-Meldungshandler

BOOL CDialogPrinterOptions::OnInitDialog()
{
    CDialog::OnInitDialog();

    // Maik Jurkait [29.12.2004]
    //===========================================
    // Get default settings
    //===========================================
    ms_options.mb_styles =  0 == GETOPTION(_T("PrintNoStyles"));
    int val = GETOPTION(_T("PrintAllStyles"));
    if (val == 0) val = mpc_doc->GetOption(_T("ShowAllStyles"))*2-1;
    ms_options.mb_all_styles = 1 == val;
    ms_options.me_style_sort = (enum_style_sort)GETOPTION(_T("PrintStyleSort"));

    ms_options.mb_spells =  0 == GETOPTION(_T("PrintNoSpells"));
    val = GETOPTION(_T("PrintAllSpells"));
    if (val == 0) val = mpc_doc->GetOption(_T("ShowAllSpells"))*2-1;
    ms_options.mb_all_spells = 1 == val;
    ms_options.mb_spell_description = 0 == GETOPTION(_T("PrintSpellDesc"));

    ms_options.mb_ras = 0 == GETOPTION(_T("PrintNoRAs"));
    ms_options.mb_all_ras = 0 != GETOPTION(_T("PrintAllRAs"));;


    // Maik Jurkait [29.12.2004]
    //===========================================
    // Fill combos
    //===========================================
    int idx;
    CString temp;

    temp.LoadString(IDS_PRINTER_SORT_LINE_AND_LEVEL);
    idx = mwnd_style_sort.AddString(temp);
    mwnd_style_sort.SetItemData(idx, ESTYLE_SORT_LINEandLEVEL);
    temp.LoadString(IDS_PRINTER_SORT_LINE_AND_PRE);
    idx = mwnd_style_sort.AddString(temp);
    mwnd_style_sort.SetItemData(idx, ESTYLE_SORT_LINEandPRESTYLE);
    temp.LoadString(IDS_PRINTER_SORT_LEVEL);
    idx = mwnd_style_sort.AddString(temp);
    mwnd_style_sort.SetItemData(idx, ESTYLE_SORT_LEVEL);
    temp.LoadString(IDS_PRINTER_SORT_PRE);
    idx = mwnd_style_sort.AddString(temp);
    mwnd_style_sort.SetItemData(idx, ESTYLE_SORT_PERQUISITE);



    // Maik Jurkait [29.12.2004]
    //===========================================
    // Set controlls
    //===========================================
    mwnd_styles_no.SetCheck(!ms_options.mb_styles);
    mwnd_styles_all.SetCheck(ms_options.mb_all_styles);

    mwnd_style_sort.SetCurSel(0);
    for (int t=0;t<mwnd_style_sort.GetCount();t++)
        if (mwnd_style_sort.GetItemData(t) == ms_options.me_style_sort)
        {
            mwnd_style_sort.SetCurSel(t);
            break;
        }

    if (!ms_options.mb_styles)
    {
        mwnd_styles_all.EnableWindow(FALSE);
        mwnd_style_sort.EnableWindow(FALSE);
    }

    mwnd_spells.SetCheck(!ms_options.mb_spells);
    mwnd_spells_all.SetCheck(ms_options.mb_all_spells);
    mwnd_spell_description.SetCheck(ms_options.mb_spell_description);
    if (!ms_options.mb_spells)
    {
        mwnd_spells_all.EnableWindow(FALSE);
        mwnd_spell_sort.EnableWindow(FALSE);
        mwnd_spell_description.EnableWindow(FALSE);
    }

    mwnd_no_ras.SetCheck(!ms_options.mb_ras);
    mwnd_all_ras.SetCheck(ms_options.mb_all_ras);
    if (!ms_options.mb_ras)
    {
        mwnd_all_ras.EnableWindow(FALSE);
    }



    return TRUE;
}






void CDialogPrinterOptions::OnBnClickedCheck4()
{
    ms_options.mb_styles = !mwnd_styles_no.GetCheck();
    SETOPTION(_T("PrintNoStyles"),!ms_options.mb_styles);

    mwnd_styles_all.EnableWindow(ms_options.mb_styles);
    mwnd_style_sort.EnableWindow(ms_options.mb_styles);
}


void CDialogPrinterOptions::OnBnClickedCheck5()
{
    ms_options.mb_spells = !mwnd_spells.GetCheck();
    SETOPTION(_T("PrintNoSpells"),!ms_options.mb_spells);

    mwnd_spells_all.EnableWindow(ms_options.mb_spells);
    mwnd_spell_sort.EnableWindow(ms_options.mb_spells);
    mwnd_spell_description.EnableWindow(ms_options.mb_spells);
}

void CDialogPrinterOptions::OnCbnSelchangeCombo1()
{
    int idx = mwnd_style_sort.GetCurSel();
    ASSERT(idx != CB_ERR);
    ms_options.me_style_sort = (enum_style_sort)mwnd_style_sort.GetItemData(idx);
    SETOPTION(_T("PrintStyleSort"),ms_options.me_style_sort);
}

void CDialogPrinterOptions::OnBnClickedCheck1()
{
    ms_options.mb_all_styles = BST_CHECKED==mwnd_styles_all.GetCheck();
    SETOPTION(_T("PrintAllStyles"),ms_options.mb_all_styles?1:-1);
}

void CDialogPrinterOptions::OnBnClickedCheck2()
{
    ms_options.mb_all_spells = BST_CHECKED==mwnd_spells_all.GetCheck();
    SETOPTION(_T("PrintAllSpells"),ms_options.mb_all_spells?1:-1);
}

void CDialogPrinterOptions::OnBnClickedCheck7()
{
    ms_options.mb_spell_description = BST_CHECKED==mwnd_spell_description.GetCheck();
    SETOPTION(_T("PrintSpellDesc"),ms_options.mb_spell_description);
}

void CDialogPrinterOptions::OnBnClickedCheck3()
{
    ms_options.mb_ras = BST_CHECKED != mwnd_no_ras.GetCheck();
    mwnd_all_ras.EnableWindow(ms_options.mb_ras);

    SETOPTION(_T("PrintNoRAs"),!ms_options.mb_ras);
}


void CDialogPrinterOptions::OnBnClickedCheck6()
{
    ms_options.mb_all_ras = BST_CHECKED == mwnd_all_ras.GetCheck();
    SETOPTION(_T("PrintAllRAs"),ms_options.mb_all_ras);
}
